# -*- coding: utf-8 -*-
"""
file:ch6_6定积分面积求三次函数
author: Fuwen
time: 2022/7/20 6:55
software:PyCharm
"""
import numpy as np
import matplotlib.pyplot as plt

# 原函数 y = -1/3*x**3 + x**2, 导函数 f(x) = -x**2 + 2*x
# 积分区间[-2, 4]
# 被积函数的系数
a = -1
b = 2

# 绘制被积函数的图形区域
x = np.linspace(-2, 4, 1001)
y = a * x**2 + 2 * x
plt.plot(x, y)
plt.fill_between(x, y1=y, y2=0, where=(x>=-2)&(x<=4), facecolor='lightgreen')

plt.grid()
plt.show()